import { FormSchema } from '/@/components/Form'
import { BasicColumn } from '/@/components/Table'

export const columns = (): BasicColumn[] => {
  return [
    {
      title: '序号',
      dataIndex: 'successAutoId',
    },
    {
      title: '年份',
      dataIndex: 'nf',
    },
    {
      title: '考生编号',
      dataIndex: 'ksbh',
      width: 180,
    },
    {
      title: '考生姓名',
      dataIndex: 'xm',
    },
    {
      title: '科目代码',
      dataIndex: 'kmdm',
    },
    {
      title: '科目名称',
      dataIndex: 'kmmc',
    },
    {
      title: '考试分数',
      dataIndex: 'ksfs',
      customRender({ text }) {
        return typeof text != 'number' ? '--' : text
      },
    },
    {
      title: '查分理由',
      dataIndex: 'cfly',
    },
    {
      title: '是否证实',
      dataIndex: 'sfcl',
      customRender({ text }) {
        return !text ? '--' : text === 'N' ? '否' : '是'
      },
    },
    {
      title: '是否缺考',
      dataIndex: 'qk',
      customRender({ text }) {
        return typeof text != 'number' ? '--' : text === 1 ? '是' : '否'
      },
    },
    {
      title: '是否异常',
      dataIndex: 'sfyc',
      customRender({ text }) {
        return !text ? '--' : text === 'N' ? '否' : '是'
      },
    },
    {
      title: '处理意见',
      dataIndex: 'clyj',
    },
    {
      title: '处理人姓名',
      dataIndex: 'updateName',
    },
    {
      title: '处理时间',
      dataIndex: 'updateTime',
      width: 180,
    },
    {
      title: '导入时间',
      dataIndex: 'createTime',
      width: 180,
    },
  ]
}

export const columnsImport = () => {
  return [
    {
      title: '文件名',
      dataIndex: 'wjmc',
    },
    {
      title: '导入成功数',
      dataIndex: 'cgts',
    },
    {
      title: '导入失败数',
      dataIndex: 'sbts',
    },
    {
      title: '总条数',
      dataIndex: 'zts',
    },
    {
      title: '导入时间',
      dataIndex: 'createTime',
    },
  ]
}

import { getKmSimpAlleList } from '/@/api/organization/subjectManage'

export const formSchemas = (): FormSchema[] => {
  return [
    {
      field: 'kmdm',
      label: '科目代码',
      colProps: { span: 4 },
      component: 'ApiSelect',
      rulesMessageJoinLabel: true,
      componentProps: {
        api: getKmSimpAlleList,
        showSearch: true,
        resultField: 'data',
        params: {
          pageSize: 0,
        },
        treeDefaultExpandAll: true,
        fieldNames: { label: 'kmmc', value: 'kmdm' },
        successHandler: res => {
          res?.data?.filter((item: any) => {
            item.kmmc = `${item.kmdm}(${item.kmmc})`
          })
          res.data = res?.data?.sort((a: any, b: any) => a.kmdm - b.kmdm)
        },
        filterOption(input: string, option: any) {
          return option.kmmc.indexOf(input) >= 0
        },
        getPopupContainer: () => document.body,
      },
    },
    {
      field: 'ksbh',
      label: '考生编号',
      colProps: { span: 4 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'xm',
      label: '考生姓名',
      colProps: { span: 4 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'sfcl',
      label: '是否证实',
      colProps: { span: 4 },
      component: 'Select',
      defaultValue: 'N',
      rulesMessageJoinLabel: true,
      componentProps: function () {
        return {
          options: [
            { label: '是', value: 'Y' },
            { label: '否', value: 'N' },
          ],
        }
      },
    },
    {
      field: 'qk',
      label: '是否缺考',
      colProps: { span: 4 },
      component: 'Select',
      defaultValue: 0,
      rulesMessageJoinLabel: true,
      componentProps: function () {
        return {
          options: [
            { label: '是', value: 1 },
            { label: '否', value: 0 },
          ],
        }
      },
    },
    {
      field: 'sfyc',
      label: '是否异常',
      colProps: { span: 4 },
      component: 'Select',
      rulesMessageJoinLabel: true,
      componentProps: function () {
        return {
          options: [
            { label: '是', value: 'Y' },
            { label: '否', value: 'N' },
          ],
        }
      },
    },
  ]
}

export const formSchemasImport = (): FormSchema[] => {
  return [
    {
      field: 'wjmc',
      label: '文件名称',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
  ]
}

export const columnsLine = (activeKey: string): BasicColumn[] => {
  if (activeKey === 'success') {
    return [
      {
        title: '年份',
        dataIndex: 'nf',
      },
      {
        title: '考生编号',
        dataIndex: 'ksbh',
      },
      {
        title: '考生姓名',
        dataIndex: 'xm',
      },
      {
        title: '科目代码',
        dataIndex: 'kmdm',
      },
      {
        title: '科目名称',
        dataIndex: 'kmmc',
      },
      {
        title: '考试分数',
        dataIndex: 'ksfs',
      },
      {
        title: '查分理由',
        dataIndex: 'cfly',
      },
    ]
  } else {
    return [
      {
        title: '年份',
        dataIndex: 'nf',
      },
      {
        title: '考生编号',
        dataIndex: 'ksbh',
      },
      {
        title: '考生姓名',
        dataIndex: 'xm',
      },
      {
        title: '科目代码',
        dataIndex: 'kmdm',
      },
      {
        title: '科目名称',
        dataIndex: 'kmmc',
      },
      {
        title: '考试分数',
        dataIndex: 'ksfs',
      },
      {
        title: '查分理由',
        dataIndex: 'cfly',
      },
      {
        title: '失败原因',
        dataIndex: 'sbyy',
      },
    ]
  }
}

//搜索条件
export const formSchemasLine = (): FormSchema[] => {
  return [
    {
      field: 'kmdm',
      label: '科目代码',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'ksbh',
      label: '考生编号',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
    {
      field: 'xm',
      label: '考生姓名',
      colProps: { span: 6 },
      component: 'Input',
      rulesMessageJoinLabel: true,
    },
  ]
}

export function modalFormItem(activeKey: string): FormSchema[] {
  if (activeKey === 'success') {
    return [
      {
        field: 'remark',
        label: '备注',
        component: 'ShowSpan',
        colProps: { span: 12 },
      },
    ]
  } else {
    return [
      {
        field: 'remark',
        label: '备注',
        component: 'InputTextArea',
        colProps: { span: 24 },
      },
    ]
  }
}
